package com.service.store.impl;

import com.dao.store.CompanyDao;
import com.domain.store.Company;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.store.CompanyService;
import com.utils.MapperUtils;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

public class CompanyServiceImpl implements CompanyService {
    private CompanyDao companyDao;

    public void setCompanyDao(CompanyDao companyDao) {
        this.companyDao = companyDao;
    }

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<Company> findAll() {
        return companyDao.findAll();
    }

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo findAll(int page, int size) {
            Page pages = PageHelper.startPage(page,size);
            companyDao.findAll();
            return new PageInfo(pages);

    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Company findById(String id) {
        return companyDao.findById(id);
    }

    /**
     * 添加操作
     * @param company
     */
    @Override
    public void save(Company company) {

            String id = UUID.randomUUID().toString();
            company.setId(id);
           companyDao.save(company);
    }

    /**删除操作
     * @param company
     */
    @Override
    public void delete(Company company) {
      companyDao.delete(company);
    }

    /**
     * 修改操作
     * @param company
     */
    @Override
    public void update(Company company) {
       companyDao.update(company);
    }
}
